<?php

/** Zend_Controller_Action */
require_once ROOT_PATH . '/library/Soooner/Controller/WebAction.php';
require_once ROOT_PATH . '/library/Common/Sphinx/sphinxapi.php';

class IifaceController extends Soooner_Web_Controller_Action
{
	public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();    	
    }
    public function configAction()
    {
    	$id = $this->_getParam('id');//类别编号
    	$modelTypes=new Model_Tables_Types();
    	$infos0=$modelTypes->getList(1,20);
    	foreach($infos0 as $info){
    		$info["tag1"]=$modelTypes->parseTag($info["tag1"],true);
    		$info["tag2"]=$modelTypes->parseTag($info["tag2"],true);
    		$info["tag3"]=$modelTypes->parseTag($info["tag3"],true);
    		$infos1[]=$info;
    		if(!$id || $id==$info["id"]){
    			$infos[]=$info;
    		}    		
    	}
    	if(count($infos)==0){
    		$infos = $infos1;
    	}
    	//print_r($infos);exit;
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
        include $this->_dzTemplate->getFile( 'web/config.html' );
    }
    /**
     * 导出数据 
     * */
    public function exportAction(){
    	$ipad = $this->_getParam('ipad');
    	$typeid = $this->_getParam('typeid');
    	$tag1 = $this->_getParam('tag1');
    	$tag2 = $this->_getParam('tag2');
    	$tag3 = $this->_getParam('tag3');
    	$index = 1;//$this->_getParam('index');
    	$options = $GLOBALS['application']->getOptions();
    	$pageCount = 10000;//= $options["listcount"];//每页显示的条数
    	$liveport = $options["liveport"];
    	$vodport = $options["vodport"];
    	$webheader = $this->_configs["web"];
    	$pubmod = $this->_configs["pubmod"];//发布模式
    	if($webheader=="/")
    		$webheader = "http://".$this->_configs["myip"];
    	else 
    		$webheader="";	
    	$modelSlaves = new Model_Tables_Slaves();
    	$modelLvsip = new Model_Tables_Lvsvip();
    	$slavesSips = $modelSlaves->getSlavesSipList();
    	$modelTypes = new Model_Tables_Types();
    	$typeInfo = $modelTypes->getInfo($typeid);
    	$modelVodlist = new Model_Tables_Vodlist();
    	if($typeInfo["model"]=="vod"){
    		$modelVod = new Model_Tables_Vod();
    		$count = $modelVod->getCountbyTags($typeid,$tag1,$tag2,$tag3);
    		$infos = $modelVod->getListbyTags($typeid,$tag1,$tag2,$tag3,$index,$pageCount);
    		for($i=0;$i<count($infos);$i++){
    			$sipid=$infos[$i]["vodip"];
    			$sip=$slavesSips[$sipid];
    			$vid = $infos[$i]["vid"];
    			$listinfos = $modelVodlist->getAllList($vid);
    			$info = $modelVod->getInfo($vid);
    			
    			$vodproxyInfo=$modelLvsip->getproxy("PROXYVOD");//点播代理信息
		    	if($vodproxyInfo){//如果点播代理信息存在
		    		$vodheader = "http://".$vodproxyInfo["virtualipaddress"].":".$vodproxyInfo["port"]."/";
		    	}else{//代理组不存在
		    		if($pubmod=="MULTY"){//多机发布
		    			$vodInfo=$modelLvsip->getInfo($info["vodip"]);
		    			$vodheader = "http://".$vodInfo["virtualipaddress"].":".$vodInfo["port"]."/";
		    		}
		    		else{//单机发布
		    			$vodheader = "http://".$slavesSips[$info["vodip"]]["sip"].":".$slavesSips[$info["vodip"]]["vodport"]."/";
		    		}
		    	}
    			
    			//$vodheader = "http://".$sip.":".$vodport."/";
    			$infos[$i]["vodheader"]=$vodheader;
    			$infos[$i]["videos"]=$listinfos;
    			$infos[$i]["type"]="vod";
    		}
    	}else if($typeInfo["model"]=="live"){
    		$modelLive = new Model_Tables_Live();
    		$count = $modelLive->getCountbyTags($typeid,$tag1,$tag2,$tag3,$ipad);
    		$infos = $modelLive->getListbyTags($typeid,$tag1,$tag2,$tag3,$index,$pageCount,$ipad);
    		for($i=0;$i<count($infos);$i++){
    			$sipid=$infos[$i]["liveip"];
    			$sip=$slavesSips[$sipid];
    			$infos[$i]["type"]="live";
    			$info = $modelLive->getInfo($infos[$i]["vid"]);//2011-02-18
		    	$modelLvsip = new Model_Tables_Lvsvip();
		    	//直播地址
		    	$liveproxyInfo=$modelLvsip->getproxy();//直播代理信息
		    	if($liveproxyInfo){//如果直播代理组存在
		    		$liveheader = "http://".$liveproxyInfo["virtualipaddress"].":".$liveproxyInfo["port"]."/";
		    	}else{//代理组不存在
		    		if($pubmod=="MULTY"){//多机发布
		    			$liveInfo=$modelLvsip->getInfo($info["liveip"]);
		    			$liveheader = "http://".$liveInfo["virtualipaddress"].":".$liveInfo["port"]."/";
		    		}
		    		else{//单机发布
		    			$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
		     		}
		    	}
    			
		    	//时移地址
		    	$tsproxyInfo=$modelLvsip->getproxy("PROXYTS");//时移代理信息
		    	//if($tsproxyInfo){
		    	//	$tsheader = "http://".$tsproxyInfo["virtualipaddress"].":".$tsproxyInfo["port"]."/";
		    	//}else{//时移代理不使用
		    	//print_r($info);exit;
		    	if($info["tsheader"]){//只有代理模式下该字段有值
		    		$tsheader = $info["tsheader"];
		    	}
		    	else{
		    		if($pubmod=="MULTY"){//多机发布
		    			$tsInfo=$modelLvsip->getInfo($info["tsip"]);
		    			if($modelLvsip->isSon($info["tsip"],$info["liveip"])){//如果直播组所有设备同时在时移组
		    				$tsheader = "http://".$tsInfo["virtualipaddress"].":".$tsInfo["port"]."/";
		    			}
		    			else{//否则取时移组的第一台设备
		    				//echo "notson";exit;
		    				$modelLvservers = new Model_Tables_Lvsservers();
		    				$lvsserverInfo = $modelLvservers->getList(1, 1,"",$info["tsip"]);
		    				$tsheader = "http://".$lvsserverInfo[0]["serverip"].":".$lvsserverInfo[0]["port"]."/";
		    			}
		    		}
		    		else{//单机发布
		    			$tsheader = "http://".$slavesSips[$info["tsip"]]["ip"].":".$slavesSips[$info["tsip"]]["tsport"]."/";
		    		}
		    	}		    	
		    	$infos[$i]["url"]=$liveheader.$infos[$i]["vid"];//直播地址
		    	$infos[$i]["urllow"]=$liveheader.$infos[$i]["vid"]."low";//直播地址
    		}
    	}
    	
    	$countInPage = count($infos);
    	$pageCount = ceil($count/$pageCount);
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
    	include $this->_dzTemplate->getFile( 'web/export.html' );
    }
    public function listAction(){
    	$ipad = $this->_getParam('ipad');
    	$typeid = $this->_getParam('typeid');
    	$tag1 = $this->_getParam('tag1');
    	$tag2 = $this->_getParam('tag2');
    	$tag3 = $this->_getParam('tag3');
    	$index = $this->_getParam('index');
    	$pCount = $this->_getParam('pcount');
    	$options = $GLOBALS['application']->getOptions();
    	$pageCount = $options["listcount"];//每页显示的条数
    	if($ipad)
    		$pageCount = $options["ipadlistcount"];//每页显示的条数
    	if($pCount!=0)
    		$pageCount=$pCount;
    	$liveport = $options["liveport"];
    	$vodport = $options["vodport"];
    	$modelTypes = new Model_Tables_Types();
    	$typeInfo = $modelTypes->getInfo($typeid);
    	if($typeInfo["model"]=="vod"){
    		$modelVod = new Model_Tables_Vod();
    		$count = $modelVod->getCountbyTags($typeid,$tag1,$tag2,$tag3);
    		$infos = $modelVod->getListbyTags($typeid,$tag1,$tag2,$tag3,$index,$pageCount);
    		$p = "1";//跳转到1.xml
    	}else if($typeInfo["model"]=="live"){
    		$modelLive = new Model_Tables_Live();
    		$count = $modelLive->getCountbyTags($typeid,$tag1,$tag2,$tag3,$ipad);
    		$infos = $modelLive->getListbyTags($typeid,$tag1,$tag2,$tag3,$index,$pageCount,$ipad);
    		$p = "[date]";//跳转到2010-12-02.xml(当前日期)
    	}
    	$myip = $this->_configs["myip"];
    	$countInPage = count($infos);
    	$pageCount = ceil($count/$pageCount);
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
        if($ipad=="1")
        	include $this->_dzTemplate->getFile( 'web/ipadlist.html' );
        else
    		include $this->_dzTemplate->getFile( 'web/list.html' );
    }
    public function liveAction(){
    	$vid = $this->_getParam('vid');
    	$modelLive = new Model_Tables_Live();
    	$info = $modelLive->getInfo($vid);
    	if($info["ipad"]=="1"){
    		$this->ipadAction();
    	}else{
    		$this->livewebAction();
    	}
    }
    public function livewebAction(){
    	$storeheader = $this->_configs["store"];
    	$webheader = $this->_configs["web"];
    	$vid = $this->_getParam('vid');
    	$d = $this->_getParam('d');
    	$index = $this->_getParam('index');
    	$options = $GLOBALS['application']->getOptions();
    	$pageCount = $options["livelistcount"];//每页显示的条数
    	$liveport = $options["liveport"];
    	$vodport = $options["vodport"];
    	$modelLive = new Model_Tables_Live();
    	$info = $modelLive->getInfo($vid);
    	
    	$pubmod = $this->_configs["pubmod"];//发布模式
    	$modelSlaves = new Model_Tables_Slaves();
    	$slavesSips = $modelSlaves->getAllSlavesList();
    	//是否有直播代理组，如果有，直接使用代理组
    	//如果无代理，判断是否是多机模式，

    	$modelLvsip = new Model_Tables_Lvsvip();
    	//直播地址
    	$liveproxyInfo=$modelLvsip->getproxy();//直播代理信息
    	if($liveproxyInfo){//如果直播代理组存在
    		$liveheader = "http://".$liveproxyInfo["virtualipaddress"].":".$liveproxyInfo["port"]."/";
    	}else{//代理组不存在
    		if($pubmod=="MULTY"){//多机发布
    			$liveInfo=$modelLvsip->getInfo($info["liveip"]);
    			$liveheader = "http://".$liveInfo["virtualipaddress"].":".$liveInfo["port"]."/";
    		}
    		else{//单机发布
    			$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
     		}
    	}
    	//点播地址
    	$vodproxyInfo=$modelLvsip->getproxy("PROXYVOD");//点播代理信息
    	if($vodproxyInfo){//如果点播代理信息存在
    		$vodheader = "http://".$vodproxyInfo["virtualipaddress"].":".$vodproxyInfo["port"]."/";
    	}else{//代理组不存在
    		if($pubmod=="MULTY"){//多机发布
    			$vodInfo=$modelLvsip->getInfo($info["vodip"]);
    			$vodheader = "http://".$vodInfo["virtualipaddress"].":".$vodInfo["port"]."/";
    		}
    		else{//单机发布
    			$vodheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["vodport"]."/";
    		}
    	}
    	//时移地址
    	$tsproxyInfo=$modelLvsip->getproxy("PROXYTS");//时移代理信息
    	//if($tsproxyInfo){
    	//	$tsheader = "http://".$tsproxyInfo["virtualipaddress"].":".$tsproxyInfo["port"]."/";
    	//}else{//时移代理不使用
    	//print_r($info);exit;
    	if($info["tsheader"]){//只有代理模式下该字段有值
    		$tsheader = $info["tsheader"];
    	}
    	else{
    		if($pubmod=="MULTY"){//多机发布
    			$tsInfo=$modelLvsip->getInfo($info["tsip"]);
    			if($modelLvsip->isSon($info["tsip"],$info["liveip"])){//如果直播组所有设备同时在时移组
    				//echo "son";exit;
    				$tsheader = "http://".$tsInfo["virtualipaddress"].":".$tsInfo["port"]."/";
    			}
    			else{//否则取时移组的第一台设备
    				//echo "notson";exit;
    				$modelLvservers = new Model_Tables_Lvsservers();
    				$lvsserverInfo = $modelLvservers->getList(1, 1,"",$info["tsip"]);
    				$tsheader = "http://".$lvsserverInfo[0]["serverip"].":".$lvsserverInfo[0]["port"]."/";
    			}
    		}
    		else{//单机发布
    			$tsheader = "http://".$slavesSips[$info["tsip"]]["ip"].":".$slavesSips[$info["tsip"]]["tsport"]."/";
    		}
    	}
    	//$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
    	//$vodheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["vodport"]."/";
    	//$tsheader = "http://".$slavesSips[$info["tsip"]]["ip"].":".$slavesSips[$info["tsip"]]["tsport"]."/";
    
    	
    	$info["uuid"] = $modelLive->uuid($vid,$tsheader);
    	$info["uuidlow"] = $modelLive->uuid($vid,$tsheader,true);
    	if($info["ists"]==1){
    		$modelEpg = new Model_Tables_Epg();
    		//$count = $modelEpg->getCount($d,$vid,2);
    		//$infos = $modelEpg->getList($index,$pageCount,$d,$vid,2);
    		//$count = $modelEpg->getCount($index,$vid);//页数和编号
    		$infos = $modelEpg->getListByDay($vid, $d, $index);//页数和编号
    		$count = count($infos);
    		$countInPage = count($infos);
    		//$pageCount = ceil($count/$pageCount);
    		$pageCount = 3;//显示3天的节目单
    		for($i=0;$i<count($infos);$i++){
    			$infos[$i]["flag"]=date('H:i',strtotime($infos[$i]["start"]));
    		}
    	}
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
        include $this->_dzTemplate->getFile( 'web/livedetail.html' );
    }
	public function ipadAction(){
    	//$liveheader = $this->_configs["live"];
    	$storeheader = $this->_configs["store"];
    	//$vodheader = $this->_configs["vod"];
    	$webheader = $this->_configs["web"];
    	$vid = $this->_getParam('vid');
    	$d = $this->_getParam('d');
    	$index = $this->_getParam('index');
    	$options = $GLOBALS['application']->getOptions();
    	$pageCount = $options["livelistcount"];//每页显示的条数
    	$liveport = $options["liveport"];
    	$vodport = $options["vodport"];
    	$modelLive = new Model_Tables_Live();
    	$info = $modelLive->getInfo($vid);
    	
    	$modelSlaves = new Model_Tables_Slaves();
    	$slavesSips = $modelSlaves->getAllSlavesList();
    	$pubmod = $this->_configs["pubmod"];//发布模式
		$modelLvsip = new Model_Tables_Lvsvip();
    	//直播地址
    	$liveproxyInfo=$modelLvsip->getproxy();//直播代理信息
    	if($liveproxyInfo){//如果直播代理组存在
    		$liveheader = "http://".$liveproxyInfo["virtualipaddress"].":".$liveproxyInfo["port"]."/";
    	}else{//代理组不存在
    		if($pubmod=="MULTY"){//多机发布
    			$liveInfo=$modelLvsip->getInfo($info["liveip"]);
    			$liveheader = "http://".$liveInfo["virtualipaddress"].":".$liveInfo["port"]."/";
    		}
    		else{//单机发布
    			$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
     		}
    	}
    	//点播地址
    	$vodproxyInfo=$modelLvsip->getproxy("PROXYVOD");//点播代理信息
    	if($vodproxyInfo){//如果点播代理信息存在
    		$vodheader = "http://".$vodproxyInfo["virtualipaddress"].":".$vodproxyInfo["port"]."/";
    	}else{//代理组不存在
    		if($pubmod=="MULTY"){//多机发布
    			$vodInfo=$modelLvsip->getInfo($info["vodip"]);
    			$vodheader = "http://".$vodInfo["virtualipaddress"].":".$vodInfo["port"]."/";
    		}
    		else{//单机发布
    			$vodheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["vodport"]."/";
    		}
    	}
    	//时移地址
    	$tsproxyInfo=$modelLvsip->getproxy("PROXYTS");//时移代理信息
    	if($tsproxyInfo){
    		$tsheader = "http://".$tsproxyInfo["virtualipaddress"].":".$tsproxyInfo["port"]."/";
    	}else{
    		if($pubmod=="MULTY"){//多机发布
    			$tsInfo=$modelLvsip->getInfo($info["tsip"]);
    			$tsheader = "http://".$tsInfo["virtualipaddress"].":".$tsInfo["port"]."/";
    		}
    		else{//单机发布
    			$tsheader = "http://".$slavesSips[$info["tsip"]]["ip"].":".$slavesSips[$info["tsip"]]["tsport"]."/";
    		}
    	}
    	
    	//$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
    	//$vodheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["vodport"]."/";
    	//$ipadheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["tsport"]."/";
    	    	
    	//$liveheader = "http://".$this->getSip($info["liveip"]).":".$liveport."/";
    	//$vodheader = "http://".$this->getSip($info["tsip"]).":".$vodport."/";
    	//$ipadheader = "http://".$this->getSip($info["tsip"])."/";
    	$ipadheader=$tsheader;
    	$info["uuid"] = $modelLive->uuid($vid,$storeheader);
    	if($info["ists"]==1){
    		$modelEpg = new Model_Tables_Epg();
    		$infos = $modelEpg->getListByDay($vid, $d, $index);//页数和编号
    		$count = count($infos);
    		$countInPage = count($infos);
    		$pageCount = 3;//显示3天的节目单    		
    		/*
    		$modelEpg = new Model_Tables_Epg();
    		$count = $modelEpg->getCount($d,$vid,2);
    		$infos = $modelEpg->getList($index,$pageCount,$d,$vid,2);
    		$countInPage = count($infos);
    		$pageCount = ceil($count/$pageCount);*/
    		for($i=0;$i<count($infos);$i++){
    			$infos[$i]["s"]=date('YmdHis',strtotime($infos[$i]["start"]));
    			$infos[$i]["e"]=date('YmdHis',strtotime($infos[$i]["end"]));
    		}
    	}    	
    	header("Content-Type: text/xml");
   		$header="<?xml version='1.0' encoding='utf-8' ?>\n";
        include $this->_dzTemplate->getFile( 'web/ipaddetail.html' );
    }
    public function vodAction(){
    	//$vodheader = $this->_configs["vod"];
    	$vid = $this->_getParam('vid');
    	$index = $this->_getParam('index');
    	$options = $GLOBALS['application']->getOptions();
    	$pageCount = $options["vodlistcount"];//每页显示的条数
    	$vodport = $options["vodport"];
    	$modelVod = new Model_Tables_Vod();
    	$info = $modelVod->getInfo($vid);
    	
    	$modelType = new Model_Tables_Types();
    	$typeinfo = $modelType->getInfo($info["type"]);
    	$linenum = $typeinfo["linenum"];
    	$listtitle = "";
    	if($linenum==1)$listtitle="专题列表";
    	elseif($linenum==3)$listtitle="剧集列表";
    	$modelSlaves = new Model_Tables_Slaves();
    	$slavesSips = $modelSlaves->getAllSlavesList();
    	
    	
    	$pubmod = $this->_configs["pubmod"];//发布模式
    	$modelLvsip = new Model_Tables_Lvsvip();
    	//点播地址
    	$vodproxyInfo=$modelLvsip->getproxy("PROXYVOD");//点播代理信息
    	if($vodproxyInfo){//如果点播代理信息存在
    		$vodheader = "http://".$vodproxyInfo["virtualipaddress"].":".$vodproxyInfo["port"]."/";
    	}else{//代理组不存在
    		if($pubmod=="MULTY"){//多机发布
    			$vodInfo=$modelLvsip->getInfo($info["vodip"]);
    			$vodheader = "http://".$vodInfo["virtualipaddress"].":".$vodInfo["port"]."/";
    		}
    		else{//单机发布
    			$vodheader = "http://".$slavesSips[$info["vodip"]]["sip"].":".$slavesSips[$info["vodip"]]["vodport"]."/";
    		}
    	}
    	//点播地址结束
    	//$vodheader = "http://".$slavesSips[$info["vodip"]]["sip"].":".$slavesSips[$info["vodip"]]["vodport"]."/";
    	//$vodheader = "http://".$this->getSip($info["vodip"]).":".$vodport."/";
    	//if($info["state"]>1){
    	$modelVodlist = new Model_Tables_Vodlist();
    	$count = $modelVodlist->getCount("",$vid);
    	$info["state"] = $count;
    	$infos = $modelVodlist->getList($index,$pageCount,"",$vid);
    	$countInPage = count($infos);
    	$pageCount = ceil($count/$pageCount);
    	//}
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
        include $this->_dzTemplate->getFile( 'web/voddetail.html' );
    }
    //生成配置文件
    public function svcAction()
    {
    	//判断本机是不是在代理组中，如果在按规则生成所有的直播节目，不时移
    	//如果不在代理组，判断发布模式是多机还是单机
    	//多机模式的配置文件
    	
    	//单机模式的配置文件
    	$modelLvsip = new Model_Tables_Lvsvip();
    	$pubmod = $this->_configs["pubmod"];
    	$modelLive = new Model_Tables_Live();
    	$infos0 = $modelLive->getList(1,100,"","0");//web
    	$infos1 = $modelLive->getList(1,100,"","1");//ipad
    	$modelMediatype = new Model_Tables_Mediatype();
    	$modelSlaves = new Model_Tables_Slaves();
    	$slavesSips = $modelSlaves->getAllSlavesList();
    	foreach($infos0 as $info){
    		$liveip = $this->getip($info["liveip"]);
    		$tsip = $this->getip($info["tsip"]);    	
    		$myip = $this->_configs["myip"];	
    		$mediaInfo = $modelMediatype->getInfo($info["urltype"]);
    		$info["mod"] = $mediaInfo["mod"];
    		$info["stype"] = $mediaInfo["stype"];
    		$info["transcoder"] = $mediaInfo["transcoder"];
    		$info["epgdelay"] = $mediaInfo["epgdelay"];
    		if($modelLvsip->ipisproxy($myip))//代理组,只发布直播节目
    		{
    			$info["ists"]=0;
		    	//取源的地址
	    		if($pubmod=="MULTY"){//多机发布
	    			$liveInfo=$modelLvsip->getInfo($info["liveip"]);
	    			$liveheader = "http://".$liveInfo["virtualipaddress"].":".$liveInfo["port"]."/";
	    		}
	    		else{//单机发布
	    			$liveheader = "http://".$slavesSips[$info["liveip"]]["sip"].":".$slavesSips[$info["liveip"]]["liveport"]."/";
	     		}
	     		$info["url"]=$liveheader.$info["vid"];
	     		$info["urllow"]=$liveheader.$info["vid"]."low";
	     		$infos[]=$info;	     		
    		}else{//不在代理组
    			if($pubmod=="MULTY"){//多机发布
    				//如果本机ip不是组中编号最小的ip，源使用组中最小编号的源
		    		$firstSr=$modelLvsip->firstSr($info["liveip"]);
		    		if($firstSr["serverlip"]!=$myip){
		    			$info["url"]="http://".$firstSr["serverlip"].":".$firstSr["port"]."/".$info["vid"];
		    			$info["urllow"]="http://".$firstSr["serverlip"].":".$firstSr["port"]."/".$info["vid"]."low";
		    		}
    				if($modelLvsip->ipisusetype($myip, $info["tsip"])){
		    			$infos[]=$info;
		    		}elseif ($modelLvsip->ipisusetype($myip, $info["liveip"])){
		    			$info["ists"]=0;
		    			$infos[]=$info;
		    		}
    			}else{//单机发布
    				if($myip==$tsip){
		    			$infos[]=$info;
		    		}elseif ($myip==$liveip){
		    			$info["ists"]=0;
		    			$infos[]=$info;
		    		}
    			}//单机发布结束
    		}
    				
    	}
    	foreach($infos1 as $info){
    		$liveip = $this->getip($info["liveip"]);
    		$tsip = $this->getip($info["tsip"]);    	
    		$myip = $this->_configs["myip"];	
    		$mediaInfo = $modelMediatype->getInfo($info["urltype"]);
    		//$info["streamtype"] = $mediaInfo["VMT_STREAM_TYPE"];
    		$info["mod"] = $mediaInfo["mod"];
    		$info["stype"] = $mediaInfo["stype"];
    		$info["transcoder"] = $mediaInfo["transcoder"];
    		$info["epgdelay"] = $mediaInfo["epgdelay"];

    		if($modelLvsip->ipisproxy($myip))//代理组,只发布直播节目
    		{
    			$mediaInfoProxy = $modelMediatype->getInfo(4);//(TS/ipad)
	    		//$info["streamtype"] = $mediaInfo["VMT_STREAM_TYPE"];
	    		$info["mod"] = $mediaInfoProxy["mod"];
	    		$info["stype"] = $mediaInfoProxy["stype"];
	    		$info["transcoder"] = $mediaInfoProxy["transcoder"];
	    		$info["epgdelay"] = $mediaInfoProxy["epgdelay"];
	    		
		    	//$info["ists"]=0;
		    	//取源的地址
	    		if($pubmod=="MULTY"){//多机发布
	    			$liveInfo=$modelLvsip->getInfo($info["tsip"]);
	    			$liveheader = "http://".$liveInfo["virtualipaddress"].":".$liveInfo["port"]."/";
	    		}
	    		else{//单机发布
	    			$liveheader = "http://".$slavesSips[$info["tsip"]]["sip"].":".$slavesSips[$info["tsip"]]["liveport"]."/";
	     		}
	     		$info["url"]=$liveheader."interface/ipad/vid/".$info["vid"]."/ipad.m3u8";
	     		$infos[]=$info;	 
    		}else{//不在代理组
    			if($pubmod=="MULTY"){//多机发布
    				if($modelLvsip->ipisusetype($myip, $info["tsip"])){
		    			$infos[]=$info;
		    		}elseif ($modelLvsip->ipisusetype($myip, $info["liveip"])){
		    			//$info["ists"]=0;
		    			$infos[]=$info;
		    		}
    			}else{//单机发布
    				if($myip==$tsip){
		    			$infos[]=$info;
		    		}elseif ($myip==$liveip){
		    			//$info["ists"]=0;
		    			$infos[]=$info;
		    		}
    			}//单机发布结束
    		}	
    	}
    	//print_r($infos);exit;
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
    	include $this->_dzTemplate->getFile( 'web/svc.html' );
    }
    public function switchstationAction(){
    	$ip = $this->_configs["myip"];
    	header("Content-Type: text/xml");
    	$header="<?xml version='1.0' encoding='utf-8' ?>\n";
    	include $this->_dzTemplate->getFile( 'web/SwitchStation.html' );
    }
    public function lvscnfAction(){
    	$modelLvsDC = new Model_Tables_Lvsdatacenter();
    	$cid = $this->_getParam('cid');//数据中心编号
    	$result = $modelLvsDC->getcnfInfo($cid);
    	$info = $result["info"];
    	$servers = $result["servers"];
    	$vips=array();//ip地址
    	$vipports=array();//虚拟服务
    	//获取ip
    	foreach($servers as $item){
    		$virtualipaddress=$item["virtualipaddress"];//ip
    		$port=$item["vport"];//端口
    		$vips[$virtualipaddress]=$virtualipaddress;
    		$vipports[$virtualipaddress.":".$port]["virtualipaddress"]=$virtualipaddress;
    		$vipports[$virtualipaddress.":".$port]["vport"]=$port;
    		$vipports[$virtualipaddress.":".$port]["persistencetimeout"] = $item["persistencetimeout"];
    		$vipports[$virtualipaddress.":".$port]["protocol"] = $item["protocol"];
    		$vipports[$virtualipaddress.":".$port]["lbalgo"] = $item["lbalgo"];
    		$vipports[$virtualipaddress.":".$port]["lbkind"] = $item["lbkind"];
    		$vipports[$virtualipaddress.":".$port]["delayloop"] = $item["delayloop"];
 
    		$vipports[$virtualipaddress.":".$port]["real"][]=$item;	
    	}
    	//print_r($result);
    	//print_r($vipports);
    	//获取ip结束
    	header("Content-Type: text/plain");
    	include $this->_dzTemplate->getFile( 'web/lvs.html' );
    }
    private function getSip($id){
    	$modelSlaves = new Model_Tables_Slaves();
    	$slaveinfo = $modelSlaves->getInfo($id);
    	if($slaveinfo)
    		return $slaveinfo["sip"];
    	else 
    		return "";
    }
	private function getip($id){
    	$modelSlaves = new Model_Tables_Slaves();
    	$slaveinfo = $modelSlaves->getInfo($id);
    	if($slaveinfo)
    		return $slaveinfo["ip"];
    	else 
    		return "";
    }
}